New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optionally log last known call, publish stacktrace in telemetry #3798
Optionally log last known call, publish stacktrace in telemetry #3798
Conversation
1284048
to
973e4d5
Compare
Co-authored-by: José Valim <jose.valim@gmail.com>
* `:stacktrace`- publishes the stacktrace in telemetry events and | ||
allows more advanced logging. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its a bit of a gray area because, well, this is how ecto_sql uses it, but it may be used differently elsewhere :~
lib/ecto/repo/supervisor.ex
Outdated
@@ -154,6 +154,29 @@ defmodule Ecto.Repo.Supervisor do | |||
end | |||
end | |||
|
|||
@compile {:inline, triplet: 2, maybe_put_stacktrace: 2} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the triplet
function is not used in this module the inline
annotation has no effect - it only potentially inlines the function inside of the module (it works just fine for maybe_put_stacktrace
though)
💚 💙 💜 💛 ❤️ |
Hi, @v0idpwn! Are you using this feature in development, or in production too? If you're using it in production, would you mind sharing how are you storing the stacktraces for later analysis? |
Hello, @gmile. Our intention here was improving development logs (paired with elixir-ecto/ecto_sql#366). For production environment, the existing approaches to trace and correlate queries with spans are usually more than enough in my experience. I don't know about how appsignal in particular does it, but with opentelemetry you will always be able to relate queries to calling code. |
@v0idpwn well noted on improving development logs, thanks for making this possible!
I am actively studying OpenTelemetry right now, but am failing to see an out-of-the-box (e.g. provided by a package + configuration) solution 🤔 Would you happen to have an example of how to configure Ecto + OpenTelemetry to make Ecto include Ecto stacktraces in spans? I have briefly looked into |
@gmile it doesn't include the stacktrace, but it does include the "span-trace" (I mean the tree of spans that ran the query), which is generally better than a stack-trace for most cases, no? |
@v0idpwn in the grand scheme of things, a tree of spans (together constituting, what I understand, what's known as a "a trace") is enough for most cases, I agree. But what I am looking for is more resolution, so to say. For example, I want to select a given span coming from Ecto, and be able to find the file/line that produced that span - as quickly as possible. Basically, I want to do what another person was asking in original issue here elixir-ecto/ecto_sql#364, e.g. "I need the line number in the code", but available in production. |
This PR is a response to elixir-ecto/ecto_sql#363 and elixir-ecto/ecto_sql#364.
Ecto SQL PR: elixir-ecto/ecto_sql#366
This is how logs will be displayed in Ecto SQL:
To enable this feature, one would need to put in the repo options:
If enabled, the stacktrace also gets published in its entirety in respective telemetry events. This should probably only be enabled in dev environment due to performance impact.